<?php
/**
 * View_Auth
 *
 * Класс View_Auth отвечает за вывод информации, связанной с авторизацией
 *
 * @author Дмитрий Кузьма <kouzma.d@gmail.com>
 * @version 1.0
 */
class View_Auth {
	/**
	 * Метод выводит форму регистрации
	 *
	 * @param objUser - объект данных о пользователе
	 */
	public static function getRegForm($objUser) {
    $objForm = new Form_ViewForm(array('enctype' => 'multipart/form-data', 'id' => 'signUpForm'), $objUser);
		$objForm->show();
  	  $objForm->textField(array('maxlength' => '64', 'text' => 'Username', 'required' => 1), 'login');
		  $objForm->textField(array('maxlength' => '64', 'text' => 'Email', 'required' => 1), 'e_mail');
		  $objForm->passwordField(array('maxlength' => '64', 'text' => 'Password', 'required' => 1, 'class' => 'standardText'), 'pass');
		  $objForm->passwordField(array('maxlength' => '64', 'text' => 'Retype Password', 'required' => 1, 'class' => 'standardText'), 'pass_confirmation');
		  $objForm->textField(array('maxlength' => '64', 'text' => 'Last Name', 'required' => 1), 'last_name');
		  $objForm->textField(array('maxlength' => '64', 'text' => 'First Name', 'required' => 1), 'first_name');
  	  $objForm->textField(array('maxlength' => '64', 'text' => 'Middle Name', 'required' => 1), 'middle_name');
  	  //$objForm->textField(array('maxlength' => '64', 'text' => 'Birthday', 'required' => 1), 'birthday');

  	  // Российский паспорт
  	  //$arrPassportSettings = array('maxlength' => '6', 'text' => 'Passport', 'required' => 1, 'class' => 'passportNumber', 'size' => 6);
  	 // $arrPassportCodeSettings = array('maxlength' => '4', 'text' => 'Passport', 'required' => 1, 'class' => 'passportCode', 'size' => 4);
  	  //$objForm->showBeforeField($arrPassportSettings, 'passport_number');
  	    //$objForm->textField($arrPassportCodeSettings, 'passport_code', true);  
  	    //$objForm->textField($arrPassportSettings, 'passport_number', true);
  	  //$objForm->showAfterField($arrPassportSettings, 'passport_number');
  	  
      /* Загран паспорт
  	  $arrPassportSettings = array('maxlength' => '6', 'text' => 'Travel passport', 'class' => 'passportNumber', 'size' => 6);
  	  $arrPassportCodeSettings = array('maxlength' => '4', 'text' => 'Travel passport', 'class' => 'passportCode', 'size' => 4);
  	  $arrPassportExpiryDateSettings = array('maxlength' => '10', 'text' => 'Travel passport', 'class' => 'passportExpiryDate', 'size' => 10);
  	  $objForm->showBeforeField($arrPassportSettings, 'travel_passport_number');
  	    $objForm->textField($arrPassportCodeSettings, 'travel_passport_code', true);  
  	    $objForm->textField($arrPassportSettings, 'travel_passport_number', true);
  	    $objForm->textField($arrPassportExpiryDateSettings, 'travel_passport_expiry_date', true);
  	  $objForm->showAfterField($arrPassportSettings, 'travel_passport_number');
  	  
  	  
  	  $objForm->textField(array('maxlength' => '64', 'text' => 'Position'), 'position');
  	  $objForm->textField(array('maxlength' => '64', 'text' => 'Phone number'), 'phone_number');
  	  $objForm->textField(array('maxlength' => '64', 'text' => 'Skype'), 'skype');
  	  */

  	  echo '<tr><td colspan="2">';
 		    // Загрузка картинки - начало
    		$fileFieldId = 'User_User_pic';
    		$previewBlockId = $fileFieldId . '_upload';
 		    echo '<div class="fileWithImage">';
      		echo '<p class="fileImageName">Avatar</p>';
      		echo '<div id="' . $previewBlockId . '" class="uploadedImage">';
      		  View_Profile::showAvatar($objUser->tableFields, 's_');
      		echo '</div>';
    		  $arrShowImage = array('folder' => $objUser->getField('pic_folder'), 'file' => $objUser->getField('pic_file'), 'type' => 's_');
    		  self::showFileLoadBlock($objForm, $fileFieldId, 'pic', $arrShowImage);
  			echo '</div>';
				// Загрузка картинки - конец
				// Каптча - начало
    		echo '<div id="allKaptchaDiv">';
          echo '<div id="kaptchaEnterCode">';
        	  echo '<p>Enter code (<a class="reg_crypt_change ajax" onclick="javascript:document.getElementById(\'reg_crypt\').src=\'' .  W_ABSPATH . 'auth/kaptcha/\'+Math.round(Math.random(0)*1000)+1">Refresh image</a>)</p>';
      	    $objForm->textField(array('maxlength' => '10', 'text' => 'Enter code', 'required' => 0, 'value' => '' , 'class' => 'kaptchaInput'), 'kaptcha', true);
          echo '</div>';
       		echo '<div id="kaptchaImageDiv">';
        		  echo '<img src="' . W_ABSPATH . 'auth/kaptcha/" class="kaptcha" id="reg_crypt" alt="" />';
       		echo '</div>';
       	echo '</div>';
       	// Каптча - конец
    echo '</td></tr>';

	  $objForm->checkbox(array('label' => 'I agree to the Terms of Use', 'text' => 'User agreement', 'required' => 1), 'confirm');
		$objForm->submitButton(array('value' => 'Register'), 'save');
		$objForm->close();
	}
	
	public static function getRegFormTC($objUser) {
	  $objForm = new Form_Form(array('enctype' => 'multipart/form-data', 'id' => 'signUpForm', 'class' => 'smallInputs'), $objUser);
		$objForm->show();
	    
		// 1. Доступ к аккаунту
		View_Block::showBorderWithHeaderOpen('Доступ к аккаунту');
	    echo '<table cellspacing="0" class="tableWithHorInputs">';
	      echo '<tr>';
	        echo '<th>';
	          echo 'Логин';
	        echo '</th>';
	        echo '<th>';
	          echo 'Эл. почта';
	        echo '</th>';
	        echo '<th>';
	          echo 'Пароль';
	        echo '</th>';
	        echo '<th>';
	          echo 'Повторите пароль';
	        echo '</th>';
	      echo '</tr>';
	      echo '<tr>';
	        echo '<td>';
        	  $objForm->textField(array('maxlength' => '64', 'text' => 'Username', 'required' => 1), 'login');
	        echo '</td>';
	        echo '<td>';
	          $objForm->textField(array('maxlength' => '64', 'text' => 'Email', 'required' => 1), 'e_mail');
	        echo '</td>';
	        echo '<td>';
	          $objForm->passwordField(array('maxlength' => '64', 'text' => 'Password', 'required' => 1, 'class' => 'standardText'), 'pass');
	        echo '</td>';
	        echo '<td>';
	          $objForm->passwordField(array('maxlength' => '64', 'text' => 'Retype Password', 'required' => 1, 'class' => 'standardText'), 'pass_confirmation');
	        echo '</td>';
	      echo '</tr>';
	    echo '</table>';
	    View_Block::showBorderWithHeaderClose();
	    
	    /*
	    //2. Информация о ТопКлиенте
	    View_Block::showBorderWithHeaderOpen('2. Информация о пользователе');
	    echo '<table cellspacing="0" class="tableWithHorInputs">';
	      echo '<tr>';
	        echo '<th>';
	          echo 'Фамилия';
	        echo '</th>';
	        echo '<th>';
	          echo 'Имя';
	        echo '</th>';
	        echo '<th>';
	          echo 'Отчество';
	        echo '</th>';
	      echo '</tr>';
	      echo '<tr>';
	        echo '<td>';
   	  		  $objForm->textField(array('maxlength' => '64', 'text' => 'Last Name', 'required' => 1), 'last_name');
	        echo '</td>';
	        echo '<td>';
	          $objForm->textField(array('maxlength' => '64', 'text' => 'First Name', 'required' => 1), 'first_name');
	        echo '</td>';
	        echo '<td>';
	          $objForm->textField(array('maxlength' => '64', 'text' => 'Middle Name', 'required' => 1), 'middle_name');
	        echo '</td>';
	      echo '</tr>';
	    echo '</table>';
	    View_Block::showBorderWithHeaderClose();	       
	    */ 
	        /*
	        echo '<td>';
	          $objForm->textField(array('maxlength' => '64', 'text' => 'Birthday', 'required' => 1, 'class' => 'backgroundCalendar'), 'birthday');
	        echo '</td>';
	      echo '</tr>';
	      echo '<tr>';
	        echo '<th></th>';
	        echo '<th colspan="3">';
	          echo 'Серия &nbsp; &nbsp; &nbsp; Номер';
	        echo '</th>';
	      echo '</tr>';
	      echo '<tr>';
	        echo '<td>';
   	  		  echo '<b>Российский паспорт</b>';
	        echo '</td>';
	        echo '<td>';
	          $arrPassportSettings = array('maxlength' => '6', 'text' => 'Passport', 'required' => 1, 'class' => 'passportNumber', 'size' => 6);
  	        $arrPassportCodeSettings = array('maxlength' => '4', 'text' => 'Passport', 'required' => 1, 'class' => 'passportCode', 'size' => 4, 'style' => 'width:35px;');
	          $objForm->textField($arrPassportCodeSettings, 'travel_passport_code', true);  
  	        $objForm->textField($arrPassportSettings, 'travel_passport_number', true);
	        echo '</td>';
	        echo '<td colspan="2"></td>';
	      echo '</tr>';
	      echo '<tr>';
	        echo '<th></th>';
	        echo '<th>';
	          echo 'Серия &nbsp; &nbsp; &nbsp; Номер';
	        echo '</th>';
	        echo '<th>Срок окончания</th>';
	        echo '<th></th>';
	      echo '</tr>';
	      echo '<tr>';
	        echo '<td>';
   	  		  echo '<b>Заграничный паспорт</b>';
	        echo '</td>';
	        echo '<td>';
            $arrPassportSettings = array('maxlength' => '6', 'text' => 'Travel passport', 'class' => 'passportNumber', 'size' => 6);
  	        $arrPassportCodeSettings = array('maxlength' => '4', 'text' => 'Travel passport', 'class' => 'passportCode', 'size' => 4, 'style' => 'width:35px;');
	          $objForm->textField($arrPassportCodeSettings, 'travel_passport_code', true);  
      	    $objForm->textField($arrPassportSettings, 'travel_passport_number', true);
	        echo '</td>';
	        echo '<td>';
	          $arrPassportExpiryDateSettings = array('maxlength' => '10', 'text' => 'Travel passport', 'class' => 'passportExpiryDate backgroundCalendar', 'size' => 10);
	          $objForm->textField($arrPassportExpiryDateSettings, 'travel_passport_expiry_date', true);
	        echo '</td>';
	        echo '<td></td>';
	      echo '</tr>';
	    echo '</table>';
	    View_Block::showBorderWithHeaderClose();
	    
		// 3. Дополнительная информация
		View_Block::showBorderWithHeaderOpen('3. Дополнительная информация');
	    echo '<table cellspacing="0" class="tableWithHorInputs">';
	      echo '<tr>';
	        echo '<th>';
	          echo 'Телефон';
	        echo '</th>';
	        echo '<th>';
	          echo 'Скайп';
	        echo '</th>';
	        echo '<th>';
	          echo 'Должность';
	        echo '</th>';
	      echo '</tr>';
	      echo '<tr>';
	        echo '<td>';
        	  $objForm->textField(array('maxlength' => '64', 'text' => 'Phone number'), 'phone_number');
	        echo '</td>';
	        echo '<td>';
	          $objForm->textField(array('maxlength' => '64', 'text' => 'Skype'), 'skype');
	        echo '</td>';
	        echo '<td>';
	          $objForm->textField(array('maxlength' => '64', 'text' => 'Position'), 'position');
	        echo '</td>';
	      echo '</tr>';
	      echo '<tr><th colspan="3">Фотография (аватар)</th></tr>';
	      echo '<tr>';
	        echo '<td colspan="3">';
        	  
	          // Загрузка картинки -начало	
	          $fileFieldId = 'User_User_pic';
        		$filePathContainerId = $fileFieldId . '_show_path';
        		$linkToDeleteId = $fileFieldId . '_delete';
        		$previewBlockId = $fileFieldId . '_upload';
     		    echo '<div class="fileWithImage">';
          		echo '<div id="' . $previewBlockId . '" class="uploadedImage">';
          		  View_Profile::showAvatar($objUser->tableFields, 's_');
          		echo '</div>';
        		  echo '<div class="uploadWidget">';
          		  echo '<div class="uploadWidgetBrowse">';
          		  $imageArr =  array('folder' => $objUser->getField('pic_folder'), 'file' => $objUser->getField('pic_file'), 'type' => 's_');
            		  $folder = isset($arrSettings['showImage']['folder']) ? $arrSettings['showImage']['folder'] : null;
            		  $file = isset($arrSettings['showImage']['file']) ? $arrSettings['showImage']['file'] : null;
            		  $type = isset($arrSettings['showImage']['type']) ? $arrSettings['showImage']['type'] : '';
            		  $style = isset($arrSettings['showImage']['style']) ? $arrSettings['showImage']['style'] : '';
            		  if ($folder && $file) {
            		    Image::showSavedImage($folder, $file, $type, $style);
            		    echo '<br />';
            		  }
                  
            		  $objForm->fileField(array('text' => 'Photo', 'class' => 'uploadWidgetInput', 'js' => 'onchange="$(\'#' . $filePathContainerId . '\').html(this.value);ajaxFileUpload(\'' . $fileFieldId . '\');"'), 'pic', true);
         		    echo '</div>';
          		  echo '<div class="uploadWidgetContainer">';
          		    echo '<div class="uploadWidgetValue" id="' . $filePathContainerId . '"></div>';
          		  echo '</div>';
          		  echo '<div id="' . $linkToDeleteId . '"></div>';
        		  echo '</div>';
      				$objForm->hiddenField(array(), 'pic_file');
      			echo '</div>';
      			// Загрузка картинки -конец
      			
	        echo '</td>';
	      echo '</tr>';
	    echo '</table>';
	    View_Block::showBorderWithHeaderClose();
*/	    
		// Каптча - начало
		echo '<div id="allKaptchaDiv">';
      echo '<div id="kaptchaEnterCode">';
    	  echo '<p id="refreshKaptchaRow">Введите код с картинки (<a class="reg_crypt_change ajax" onclick="javascript:document.getElementById(\'reg_crypt\').src=\'' .  W_ABSPATH . 'auth/kaptcha/\'+Math.round(Math.random(0)*1000)+1">Обновить</a>)</p>';
  	    $objForm->textField(array('maxlength' => '10', 'text' => 'Введите код с картинки', 'required' => 0, 'value' => '' , 'class' => 'kaptchaInput'), 'kaptcha', true);
      echo '</div>';
   		echo '<div id="kaptchaImageDiv">';
    		  echo '<img src="' . W_ABSPATH . 'auth/kaptcha/" class="kaptcha" id="reg_crypt" alt="" />';
   		echo '</div>';
   	echo '</div>';
   	// Каптча - конец


	  //$objForm->checkbox(array('label' => '<b>I agree to the Terms of Use</b>', 'text' => 'User agreement', 'required' => 1), 'confirm');

	  
		echo '<p id="registButton">';
		  $objForm->submitButton(array('value' => 'Register', 'src' => W_IMAGES . 'button/regist.gif'), 'save');
		echo '</p>';
		
	  $objForm->close();
	}

	/**
	 * Метод выводит форму восстановления пароля
	 *
	 * @param objUser - объект данных о пользователе
	 */
	public static function getRecoveryForm($objUser) {
		$objForm = new Form_Form(array('action' => W_ABSPATH . 'auth/recovery/', 'id' => 'recoveryPageForm'), $objUser);
		$objForm->show();
		  View_Block::showBorderOpen('standardBorder', 'recoverPadding');
        echo '<p>Электронная почта</p>';
        echo '<p>';
    		  $objForm->textField(array('maxlength' => '64', 'text' => 'Email', 'required' => 1), 'e_mail', true);
    		echo '</p>';
  
    		// Каптча - начало
    		echo '<div id="allKaptchaDiv">';
          echo '<div id="kaptchaEnterCode">';
        	  echo '<p id="refreshKaptchaRow">Введите код с картинки (<a class="reg_crypt_change ajax" onclick="javascript:document.getElementById(\'reg_crypt\').src=\'' .  W_ABSPATH . 'auth/kaptcha/\'+Math.round(Math.random(0)*1000)+1">Обновить</a>)</p>';
      	    $objForm->textField(array('maxlength' => '10', 'text' => 'введите код с картинки', 'required' => 0, 'value' => '' , 'class' => 'kaptchaInput'), 'kaptcha', true);
          echo '</div>';
       		echo '<div id="kaptchaImageDiv">';
        		  echo '<img src="' . W_ABSPATH . 'auth/kaptcha/" class="kaptcha" id="reg_crypt" alt="" />';
       		echo '</div>';
       	echo '</div>';
       	// Каптча - конец
    
    	View_Block::showBorderClose();
  		echo '<p id="recoverButton">';
		    $objForm->submitButton(array('value' => 'Recover', 'src' => W_IMAGES . 'button/send.gif', 'class' => 'sendButton'), 'recover');
		  echo '</p>';
	  $objForm->close();
	}


	/**
	 * Метод выводит форму входа
	 *
	 * @param objUser - объект данных о пользователе
	 */
	public static function getLoginForm($objUser) {

		$objForm = new Form_ViewForm(array('action' => W_ABSPATH . 'auth/sign_in/', 'id' => 'loginPageForm'), $objUser);
		$objForm->show();
			echo '<p>Username or Email address</p>';
			echo '<p>';
	  	  $objForm->textField(array('maxlength' => '64', 'text' => 'Username or Email address', 'required' => 1, 'z-index' => 1, 'class' => 'standardText bigSignIn'), 'login', true);
	  	echo '</p>';

      echo '<p>Password (<a href="' . W_ABSPATH . 'auth/recovery/" title="Get new password">Забыли ваш пароль?</a>)</p>';
      echo '<p>';
    	  $objForm->passwordField(array('maxlength' => '64', 'text' => 'Password', 'required' => 1, 'z-index' => 2, 'class' => 'standardText bigSignIn'), 'pass', true);
    	echo '</p>';

      echo '<p>';
	      $objForm->checkbox(array('label' => '<strong> Do NOT</strong> remember me', 'z-index' => 3), 'no_save', true);
    	echo '</p>';

    	echo '<p>';
	 		  $objForm->submitButton(array('value' => 'Sign in', 'class' => 'relTop15px', 'z-index' => 4), 'enter', true);
	 		echo '</p>';
		$objForm->close();
	}
	
  public static function showFileLoadBlock($objForm, $fileFieldId, $fileName = 'pic', $arrShowImage = array()) {
    $filePathContainerId = $fileFieldId . '_show_path';
    $linkToDeleteId = $fileFieldId . '_delete';
    $arrSettings = array('text' => 'Photo', 'class' => 'uploadWidgetInput', 'js' => 'onchange="$(\'#' . $filePathContainerId . '\').html(this.value);ajaxFileUpload(\'' . $fileFieldId . '\');"');
    if ($arrShowImage) $arrSettings['showImage'] = $arrShowImage;
    echo '<div class="uploadWidget' . ($arrShowImage ? null : ' uploadWidgetWithoutImage') . '">';
		  echo '<div class="uploadWidgetBrowse">';
        $objForm->fileField($arrSettings, $fileName, true);
		    echo '</div>';
		  echo '<div class="uploadWidgetContainer">';
		    echo '<div class="uploadWidgetValue" id="' . $filePathContainerId . '"></div>';
		  echo '</div>';
		  echo '<div id="' . $linkToDeleteId . '"></div>';
	  echo '</div>';
		$objForm->hiddenField(array(), $fileName . '_file');
  }
}